#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(int argc, char const *argv[])
{
    pid_t pid = fork();

    if (pid>0)
    {
        int result=0;
        printf("父进程开始\n");

        waitpid(pid,&result,0);//阻塞等待子进程结束
    }else if (pid==0){
        printf("子进程开始\n");

        char *path="/bin/ping";
        char *argv[]={"ping","-c","3","www.baidu.com",NULL};
        int result = execve(path,argv,NULL);
        if (result==-1){
            perror("execve");
        }
        printf("子进程结束\n");
    }

    printf("父进程结束了\n");
    
    return 0;
}
